home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9527 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.6 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.ada,comp.lang.c
  4. Subject: Re: C/C++ knocks the crap out of Ada
  5. Date: 11 Mar 1996 08:52:24 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4i1lo8INNf82@keats.ugrad.cs.ubc.ca>
  8. References: <TANMOY.96Mar9095253@qcd.lanl.gov> <Do40oA.2EJ.0.-s@inmet.camb.inmet.com>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <Do40oA.2EJ.0.-s@inmet.camb.inmet.com>,
  12. Tucker Taft <stt@houdini.camb.inmet.com> wrote:
  13. >Tanmoy Bhattacharya (tanmoy@qcd.lanl.gov) wrote:
  14. >: ...
  15. >: And by the way, from my experience, the most common kind of errors are
  16. >: not those that can be statically or dynamically `checked'. I did
  17. >: occasionally have off by one errors leading to array bound violations,
  18. >: but, by far, the more important kinds of errors were what one would
  19. >: call `logic errors'. What I wrote made sense, and probably would have
  20. >: made sense in every language I expressed myself, but it was not what I
  21. >: wanted to code. ...
  22. >
  23. >I have heard this comment many times from people who have never
  24. >used a compiler (like every Ada compiler) that inserts run-time 
  25. >consistency checks.  However, once you use such a compiler, the
  26. >empirical evidence is that consistency checks *do* catch many logic 
  27. >errors.  The basic reason is that an "illogical" program is in most cases
  28. >also "inconsistent" at the low level.  For example, if you declare
  29. >a subtype to have the range 0..30, an illogical program will often
  30. >end up producing a value outside this range.
  31.  
  32. Ah yes; this is one thing I miss when working with C. That _can_ catch a lot of
  33. errors, and I use such range types whenever they are available in a language
  34. for array indices and all kinds of bounded values.
  35.  
  36. >This is most easily demonstrated by experience.  It is not easy to 
  37. >convince someone who has never tried such a compiler.  You seem
  38. >open to giving one a try, and I encourage you to do so.
  39.  
  40. I can't speak for Tanmoy, but I have used such featuers, having done quite a
  41. bit of Modula-2 coding once upon a time. Such range checks can help greatly,
  42. but again, they are not all powerful.
  43.  
  44. Recently, I had a good laugh when the 'p2c' compiler translated a Pascal 1..100
  45. integer type into a C unsigned char.
  46.  
  47. The closest thing you can do for checking ranges and other conditions in
  48. standard C is use the <assert.h> facility, which is ugly, and requires
  49. discipline to use. It does get you the results if you apply it consistently,
  50. but it's nothing like having a compiler _know_ what the range of an integer
  51. ought to be and automatically generate a check when given the option. 
  52. -- 
  53.  
  54.